mui.init({
	swipeBack:false,//右滑关闭功能
});
if(window.plus){
    plusReady();
}else{
    document.addEventListener('plusready',plusReady,false);
}
var bizType="",bizNo="";
function plusReady(){
	var current=plus.webview.currentWebview();
	bizType = current.bizType;
	bizNo = current.bizNo;
	var splx=current.splx;
	var bizname=current.bizName;
	$("#zclist_title").text(bizname);
	if(splx=="dsp"){
        $("#btn_canapproval").hide();
	}else{
		$("#btn_approval").hide();$("#btn_back").hide();
	}
	loadDetailData(bizNo,bizType);
	
	//返回首页
	document.getElementById('home').addEventListener('tap', function() {
	    var h=plus.webview.getWebviewById('mainpage');
	    plus.webview.show(h);
	    mui.fire(h,'tabClick',{tabId:'defaultTab'});
	});
	//退回操作
	document.getElementById("btn_back").addEventListener('tap',function (e){
		
		e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
		var btnArray=["确定","取消"];
		mui.prompt("请输入退回原因：","必填","退回原因",btnArray,function (e){
			if (e.index==0) {
				//输入框的值 e.value
				if (e.value==null || e.value=="") {
					mui.toast("请输入退回原因");
					return;
				} else{
					var param = e.value;
					var token = plus.storage.getItem("token");
					//console.log(bizNo);
					if (token==null || token=="") {
						return;
					} else{
						mui.ajax(baseServerAdrr+"/zc/returnSPB",{
							data : {
								token : token,
								bizNo : bizNo,
								bizType : bizType,
								txt : param
							},
							dataType : "json",
							type : "post",
							timeout : 30000,
							success : function (data){
								if (data.code == "success") {
									mui.toast(data.message);
									
									var h = plus.webview.getWebviewById("zcxtsplb");
									plus.webview.show(h);
									mui.fire(h,"loadListData");
								} else{
									mui.toast(data.message);
								}
							},
							error : function (xhr,type,errorThrown){
								mui.toast("服务器异常登录失败!");
							}
						});
					}
				}
				
			} else{
				mui.toast("您取消了操作！") ;
			}
		});
	});
	
}
//下边是实现审批
function approval(){
	if (bizNo=="" || bizType=="") {
		mui.toast("参数出错");
		return;
	}
	//console.log(bizNo);
	var token = plus.storage.getItem("token");
	if (token==null || token == "") {
		return;
	}else{
		mui.ajax(baseServerAdrr+"/zc/approveSPB",{
			data : {
				token : token ,
				bizType : bizType,
				bizNo : bizNo
			},
			dataType : "json",
			type:"post",
			timeout:30000,
			success:function(data){
				if (data.code=="success") {
					mui.toast(data.message);
					var h = plus.webview.getWebviewById("zcxtsplb");
					plus.webview.show(h);
					mui.fire(h,"loadListData");
				} else{
					mui.toast(data.message);
//					setTimeout(function(){
//						panUtil.ReLogin();
//					},1000);
				}
			},
			error:function(xhr,type,errorThrown){
				mui.toast("服务器异常登录失败! zcspdetail.js");
			}
		});
	}
}

//下边是实现取消审批
function cancleapproval(){
	if (bizNo=="" || bizType=="") {
		mui.toast("参数出错");
		return;
	}
	console.log(bizNo);
	var token = plus.storage.getItem("token");
	if (token==null || token == "") {
		return;
	}else{
		mui.ajax(baseServerAdrr+"/zc/cancleApproval",{
			data : {
				token : token ,
				bizType : bizType,
				bizNo : bizNo
			},
			dataType : "json",
			type:"post",
			timeout:3000,
			success:function(data){
				if (data.code=="success") {
					mui.toast(data.message);
					var h = plus.webview.getWebviewById("zcsplbyb");
					plus.webview.show(h);
					mui.fire(h,'loadListData');
				} else{
					mui.toast(data.message);
				}
			},
			error:function(xhr,type,errorThrown){
				mui.toast("服务器异常登录失败! zcspdetail.js");
			}
		});
	}
}

//加载自身页面信息
function loadDetailData(bizNo,bizType) {
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/zc/getDJDetail',{
	   data: {
	   		token:token,
	   		bizNo:bizNo,
	   		bizType:bizType
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data){
		   panUtil.ajaxLoding.stop();
		   if(data.code=='success'){
		   	    initlist(data.message);
		   }else{
		   	    mui.toast(data.message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! zcspdetail.js');
	    }
		});
	}
}


function detailclick(){
	console.log("test");
}
//重写返回事件
var old_back = mui.back;
mui.back = function(){
   var h=plus.webview.getWebviewById("zctoDoTab.html");
   mui.fire(h,"loadTodoData");
   //继续当前页面原有返回逻辑
   old_back();
}
function initlist(datas){
	switch (bizType){
		case "BF": initBF(datas);break;
		case "PK": initPK(datas);break;
		case "PY": initPY(datas);break;
		case "WX": initWX(datas);break;
		case "XZ": initXZ(datas);break;
		case "ZR": initZR(datas);break;
		default: break;
	}
}

function initBF(datas){
	var tablestr="";
    for (var i=0;i<datas.length;i++) {
    	var ms=datas[i];
    	tablestr+='<div class="alert alert-success">';
    	tablestr+='<span class="alert-title">资产编号:</span><span class="alert-content">'+ms.ASSET_NO+'</span><br/>';
		tablestr+='<span class="alert-title">资产名称:</span><span class="alert-content">'+ms.ASSET_NAME+'</span><br/>';
		tablestr+='<span class="alert-title">购建时间:</span><span class="alert-content">'+ms.ZCJZR+'</span><br/>';
		tablestr+='<span class="alert-title">资产原值:</span><span class="alert-content">'+ms.ZCYZ+'</span><br/>';
		tablestr+='<span class="alert-title">资产净值:</span><span class="alert-content">'+ms.ZCJZ+'</span><br/>';
		tablestr+='<span class="alert-title">使用单位:</span><span class="alert-content">'+ms.DEPT+'</span><br/>';
		tablestr+='<span class="alert-title">原因:</span><span class="alert-content">'+ms.REASON+'</span></div>';
    }
    $("#alert_block").html(tablestr);
}

function initPK(datas){
	var tablestr="";
    for (var i=0;i<datas.length;i++) {
    	var ms=datas[i];
    	tablestr+='<div class="alert alert-success">';
    	tablestr+='<span class="alert-title">资产编号:</span><span class="alert-content">'+ms.ASSET_NO+'</span><br/>';
		tablestr+='<span class="alert-title">资产名称:</span><span class="alert-content">'+ms.ASSET_NAME+'</span><br/>';
		tablestr+='<span class="alert-title">资产价值日:</span><span class="alert-content">'+ms.ZCJZR+'</span><br/>';
		tablestr+='<span class="alert-title">资产原值:</span><span class="alert-content">'+ms.ZCYZ+'</span><br/>';
		tablestr+='<span class="alert-title">资产净值:</span><span class="alert-content">'+ms.ZCJZ+'</span><br/>';
		tablestr+='<span class="alert-title">使用单位:</span><span class="alert-content">'+ms.DEPT+'</span><br/>';
		tablestr+='<span class="alert-title">原因:</span><span class="alert-content">'+ms.REASON+'</span></div>';
    }
    $("#alert_block").html(tablestr);
}

function initPY(datas){
	var tablestr="";
    for (var i=0;i<datas.length;i++) {
    	var ms=datas[i];
    	tablestr+='<div class="alert alert-success">';
    	tablestr+='<span class="alert-title">资产编号:</span><span class="alert-content">'+ms.DOC_NO+'</span><br/>';
		tablestr+='<span class="alert-title">资产名称:</span><span class="alert-content">'+ms.ASSET_NAME+'</span><br/>';
		tablestr+='<span class="alert-title">资产价值日:</span><span class="alert-content">'+ms.ZCJZR+'</span><br/>';
		tablestr+='<span class="alert-title">资产原值:</span><span class="alert-content">'+ms.ZCYZ+'</span><br/>';
		tablestr+='<span class="alert-title">资产净值:</span><span class="alert-content">'+ms.ZCJZ+'</span><br/>';
		tablestr+='<span class="alert-title">使用单位:</span><span class="alert-content">'+ms.DEPT+'</span><br/>';
		tablestr+='<span class="alert-title">原因:</span><span class="alert-content">'+ms.REASON+'</span></div>';
    }
    $("#alert_block").html(tablestr);
}

function initWX(datas){
	var tablestr="";
    for (var i=0;i<datas.length;i++) {
    	var ms=datas[i];
    	tablestr+='<div class="alert alert-success">';
    	tablestr+='<span class="alert-title">资产编号:</span><span class="alert-content">'+ms.ASSET_NO+'</span><br/>';
		tablestr+='<span class="alert-title">资产名称:</span><span class="alert-content">'+ms.ASSET_NAME+'</span><br/>';
		tablestr+='<span class="alert-title">资产原值:</span><span class="alert-content">'+ms.ZCYZ+'</span><br/>';
		tablestr+='<span class="alert-title">资产净值:</span><span class="alert-content">'+ms.ZCJZ+'</span><br/>';
		tablestr+='<span class="alert-title">使用单位:</span><span class="alert-content">'+ms.DEPT+'</span><br/>';
		tablestr+='<span class="alert-title">原因:</span><span class="alert-content">'+ms.REASON+'</span></div>';
    }
    $("#alert_block").html(tablestr);
}

function initXZ(datas){
	var tablestr="";
    for (var i=0;i<datas.length;i++) {
    	var ms=datas[i];
    	tablestr+='<div class="alert alert-success">';
    	tablestr+='<span class="alert-title">资产编号:</span><span class="alert-content">'+ms.ASSET_NO+'</span><br/>';
		tablestr+='<span class="alert-title">资产名称:</span><span class="alert-content">'+ms.ASSET_NAME+'</span><br/>';
		tablestr+='<span class="alert-title">租赁期限:</span><span class="alert-content">'+ms.ZLQX+'</span><br/>';
		tablestr+='<span class="alert-title">本年租金:</span><span class="alert-content">'+ms.NZJ+'</span><br/>';
		tablestr+='<span class="alert-title">出租单位:</span><span class="alert-content">'+ms.PROVIDENAME+'</span><br/>';
		tablestr+='<span class="alert-title">承租单位:</span><span class="alert-content">'+ms.DEPT+'</span></div>';
    }
    $("#alert_block").html(tablestr);
}

function initBF(datas){
	var tablestr="";
    for (var i=0;i<datas.length;i++) {
    	var ms=datas[i];
    	tablestr+='<div class="alert alert-success">';
    	tablestr+='<span class="alert-title">资产编号:</span><span class="alert-content">'+ms.ASSET_NO+'</span><br/>';
		tablestr+='<span class="alert-title">资产名称:</span><span class="alert-content">'+ms.ASSET_NAME+'</span><br/>';
		tablestr+='<span class="alert-title">购建时间:</span><span class="alert-content">'+ms.ZCJZR+'</span><br/>';
		tablestr+='<span class="alert-title">资产原值:</span><span class="alert-content">'+ms.ZCYZ+'</span><br/>';
		tablestr+='<span class="alert-title">资产净值:</span><span class="alert-content">'+ms.ZCJZ+'</span><br/>';
		tablestr+='<span class="alert-title">使用单位:</span><span class="alert-content">'+ms.DEPT+'</span><br/>';
		tablestr+='<span class="alert-title">原因:</span><span class="alert-content">'+ms.REASON+'</span></div>';
    }
    $("#alert_block").html(tablestr);
}

function initZR(datas){
	var tablestr="";
    for (var i=0;i<datas.length;i++) {
    	var ms=datas[i];
    	tablestr+='<div class="alert alert-success">';
    	tablestr+='<span class="alert-title">资产编号:</span><span class="alert-content">'+ms.DOC_NO+'</span><br/>';
		tablestr+='<span class="alert-title">资产名称:</span><span class="alert-content">'+ms.ASSET_NAME+'</span><br/>';
		tablestr+='<span class="alert-title">租赁期限:</span><span class="alert-content">'+ms.ZLQX+'</span><br/>';
		tablestr+='<span class="alert-title">本年租金:</span><span class="alert-content">'+ms.NZJ+'</span><br/>';
		tablestr+='<span class="alert-title">出租单位:</span><span class="alert-content">'+ms.PROVIDENAME+'</span><br/>';
		tablestr+='<span class="alert-title">承租单位:</span><span class="alert-content">'+ms.DEPT+'</span></div>';
    }
    $("#alert_block").html(tablestr);
}